<!--

    Copyright (C) 2015 The Gravitee team (http://gravitee.io)

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

            http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

-->
<span mat-dialog-title>{{ isUpdate ? 'Edit an entrypoint mapping' : 'Create an entrypoint mapping' }}</span>

<form autocomplete="off" [formGroup]="mappingForm" (ngSubmit)="onSubmit()">
  <mat-dialog-content>
    <gio-banner-info>
      Add a mapping between an entry point url and a tag list. This mapping will be used on the portal to display different entry points
      depending on API tags.
    </gio-banner-info>

    <div class="form">
      <mat-form-field>
        <mat-label>Entrypoint url</mat-label>
        <input matInput formControlName="value" type="url" placeholder="https://api.mycompany.com" required />
        <mat-error *ngIf="mappingForm.get('value').hasError('required')">Entrypoint Url is required.</mat-error>
      </mat-form-field>

      <mat-form-field>
        <mat-label>Sharding tags</mat-label>
        <mat-select formControlName="tags" aria-label="Sharding tags selection" multiple required>
          <mat-option *ngFor="let tag of tags$ | async" [value]="tag.id"
            >{{ tag.name }}{{ tag.description ? ' - ' + tag.description : '' }}</mat-option
          >
        </mat-select>
        <mat-error *ngIf="mappingForm.get('tags').hasError('required')">At least one tag must be selected.</mat-error>
      </mat-form-field>
    </div>
  </mat-dialog-content>

  <mat-dialog-actions class="actions">
    <button mat-button [mat-dialog-close]="false">Cancel</button>
    <button mat-button [disabled]="mappingForm.invalid" color="primary" type="submit">Ok</button>
  </mat-dialog-actions>
</form>
